home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / printq.exe / PRINTAPP.CPP < prev    next >
C/C++ Source or Header  |  1993-05-23  |  2KB  |  74 lines

  1. #define Uses_TApplication
  2. #define Uses_TEvent
  3. #define Uses_MsgBox
  4. #include <tv.h>
  5. #include "PrintApp.h"
  6. #include <io.h>
  7.  
  8. PrintQueue* TPrintApp::printQueue = 0;
  9.  
  10. TPrintApp::TPrintApp() :
  11.         TProgInit(initStatusLine, initMenuBar, initDeskTop),
  12.         TPrintAppInit(initPrintQueue)
  13.     {
  14.     printQueue = (createPrintQueue != 0) ? createPrintQueue() : 0;
  15.     }
  16.  
  17. void TPrintApp::shutDown()
  18.     {
  19.     delete printQueue;
  20.     printQueue = 0;
  21.     TApplication::shutDown();
  22.     }
  23.  
  24. void TPrintApp::idle()
  25.     {
  26.     TApplication::idle();
  27.     if(printQueue != 0)
  28.         printQueue->print();
  29.     }
  30.  
  31. Boolean TPrintApp::valid(ushort cmd)
  32.     {
  33.     if(cmd == cmQuit && printQueue != 0 && printQueue->currentJob() != 0)
  34.         {
  35.         if(messageBox("Still printing - cancel all printing?", mfYesNoCancel|mfWarning) == cmYes)
  36.             {
  37.             printQueue->killAll();
  38.             return True;
  39.             }
  40.         else
  41.             return False;
  42.         }
  43.     else
  44.         return TApplication::valid(cmd);
  45.     }
  46.  
  47. void TPrintApp::handleEvent(TEvent& event)
  48.     {
  49.     TApplication::handleEvent(event);
  50.     if(event.what == evCommand && event.message.command == cmAddPrintJob)
  51.         {
  52.         PrintJob* pj = (PrintJob*) event.message.infoPtr;
  53.         if(pj != 0 && pj->complete())
  54.             {
  55.             delete pj;
  56.             pj = 0;
  57.             }
  58.         if(pj != 0 && printQueue != 0 && printQueue->insert(pj))
  59.             clearEvent(event);
  60.         else
  61.             delete pj;
  62.         }
  63.     }
  64.  
  65. PrintQueue* TPrintApp::initPrintQueue()
  66.     {
  67.     return new TPrintQueue;
  68.     }
  69.  
  70. int TPrintQueue::printString(const char* str, int length) const
  71.     {
  72.     return write(4, str, length);
  73.     }
  74.